//
//  EMAgreementBottomView.m
//  EasyMoney
//
//  Created by 邓乐 on 2020/1/12.
//  Copyright © 2020 zh. All rights reserved.
//

#import "EMAgreementBottomView.h"

@interface EMAgreementCheckboxView ()


@end

@implementation EMAgreementCheckboxView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _checkbox = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox"] highlightedImage:[UIImage imageNamed:@"checkbox_selected"]];
        [self addSubview:_checkbox];
        _checkboxLabel = [[UILabel alloc] init];
        _checkboxLabel.textColor = ColorFromRGB(0x333333);
        _checkboxLabel.font = FONT_PINGFANG_REGULAR_(14);
        _checkboxLabel.text = NSLocalizedString(@"我同意这项政策", nil);
        [self addSubview:_checkboxLabel];
        _checkboxBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_checkboxBtn];
        
        [_checkbox mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(16, 16));
            make.centerY.equalTo(self);
            make.left.equalTo(self);
        }];
        [_checkboxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.right.equalTo(self);
            make.left.equalTo(_checkbox.mas_right).offset(5);
        }];
        [_checkboxBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }
    return self;
}

@end

@interface EMAgreementBottomView ()

@property (nonatomic, strong) UILabel *textLabel;

@end

@implementation EMAgreementBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    _textLabel = [[UILabel alloc] init];
    _textLabel.text = NSLocalizedString(@"请阅读整个政策", nil);
    [self addSubview:_textLabel];
    _textLabel.textColor = ColorFromRGB(0x999999);
    _textLabel.font = FONT_PINGFANG_REGULAR_(14);
    [_textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.mas_equalTo(10);
    }];
    
    _checkboxView = [[EMAgreementCheckboxView alloc] initWithFrame:CGRectZero];
    [self addSubview:_checkboxView];
    [_checkboxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.mas_equalTo(_textLabel.mas_bottom).offset(4);
    }];
    
    _btn = [UIButton buttonWithType:UIButtonTypeCustom];
    _btn.titleLabel.font = FONT_PINGFANG_MEDIUM_(16);
    _btn.layer.cornerRadius = 22;
    _btn.layer.masksToBounds = YES;
    [self addSubview:_btn];
    UIImage *image = [UIImage gradientImageSize:CGSizeMake(SCREEN_WIDTH-60-60, 44) colors:@[[UIColor colorwithHexString:@"#36B2FF"],[UIColor colorwithHexString:@"#2F5AFF"]] startPoint:CGPointMake(0, 22) endPoint:CGPointMake(SCREEN_WIDTH-60-60, 22)];
    [_btn setBackgroundImage:image forState:UIControlStateNormal];
    [_btn setTitle:NSLocalizedString(@"确定", nil) forState:UIControlStateNormal];
    [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorwithHexString:@"#2761FF" alpha:0.5]] forState:UIControlStateDisabled];
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(48);
        make.right.mas_equalTo(-48);
        make.height.mas_equalTo(44);
        make.top.equalTo(_checkboxView.mas_bottom).mas_offset(8);
    }];
    [_btn setEnabled:NO];
}



@end
